<?php
class Model_Customer_Customer extends Model_System {
	public $_name = "customer";
	protected $_sequence = true;
	public function getAll() {
		$result = $this->select();
		return $this->fetchAll($result)->toArray();
	}
	public function getAllIsActive() {
		$result = $this->select();
		$result->where('status = 1');
		return $this->fetchAll($result)->toArray();
	}
	static function getNamebyId($id)
	{
		$excute = new Model_Product_Product();
		$query = $excute->select();
		$query->where('id = ?',$id);
		$result = $excute->fetchRow($query)->toArray();
		return $result['name'];
	}
	public function getAllStartWith($char) {
		$result = $this->select();
		$result->where('email like ?','%'.$char.'%');
		$result->order("id DESC");
		return $this->fetchAll($result)->toArray();
	}
	public function changeStatusByCater($catergory)
	{
		$data = array('status'=>'0');
		$this->update($data,'category = '.$catergory);
	}
	public function changeStatus($id)
	{
		$query = $this->select();
		$query->where('id = ?',$id);
		$result = $this->fetchRow($query)->toArray();
		if($result['status']=='1')
		{
			$data = array('status'=>'0'); 
			$this->update($data, 'id = '.$id);
		}
		else
		{
			$data = array('status'=>'1'); 
			$this->update($data, 'id = '.$id);
		}
	}
	public function insertItem($data)
	{
		try {
		    $this->insert($data);
		} 
		catch (Exception $e) {
		    return $e->getMessage();
		}
		return "success";
		
	}
	public function updateItem($data,$id){
		try {
		    $this->update($data, "id = $id");
		} 
		catch (Exception $e) {
		    return $e->getMessage();
		}
		return "success";
	}
}